package com.atguigu.srb.oss.controller.api;

import com.atguigu.srb.base.response.R;
import com.atguigu.srb.oss.service.OssService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/oss")
public class ApiOssController {
    @Resource
    OssService ossService;
    //1、上传文件： 参数1-上传的文件对象  参数2-模块名称(桶内保存该文件的目录名)
    @PostMapping("upload")
    public R upload(@RequestParam("file") MultipartFile file ,
                    @RequestParam("module") String module){
        String path = ossService.upload(file,module);
        //返回上传成功的文件地址 前端数据绑定或回显
        return R.ok().data("path",path);
    }
    //2、删除文件： 参数1-文件的访问地址
    @DeleteMapping("delete")
    public R delete(@RequestParam("path")String path){
        ossService.delete(path);
        return R.ok().msg("删除成功");
    }
    //https://sh230201-srb.oss-cn-shanghai.aliyuncs.com/idCard1/2023/06-10/1686382790242_39f6e8.png
    //https://sh230201-srb.oss-cn-shanghai.aliyuncs.com/idCard1/2023/06-10/1686382790242_39f6e8.png
}
